package cst.neu.yuejian_31.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.adapter.EventAdapter;
import cst.neu.yuejian_31.bean.ActivityBean;
import cst.neu.yuejian_31.iface.EventListener;
import cst.neu.yuejian_31.model.ActivityModel;

/**
 * Created by Alienware on 2017/10/15.
 */

public class EventFragment extends BaseFragment {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private cst.neu.yuejian_31.adapter.EventAdapter EventAdapter;
    private List<ActivityBean> list=null;
    private View view=null;
    private Context context;


    EventListener EventListener=new EventListener() {
        @Override
        public void onResponse(List<ActivityBean> listbean) {
            list=listbean;
            EventAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {

            Toast.makeText(context,msg, Toast.LENGTH_SHORT).show();
        }
    };





    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_event, container, false);
        ActivityModel ActivityModel =new ActivityModel();
        ActivityModel.getActivityList(EventListener);
        init();
        return view;

    }


    private void init() {
        context=this.getActivity();
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_Event);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        EventAdapter=new EventAdapter(context);
        EventAdapter.setList(list);
        recyclerView.setAdapter(EventAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));




    }

}